<?php

/**
 * This is the model class for table "organitzador".
 *
 * The followings are the available columns in table 'organitzador':
 * @property integer $idOrganitzador
 * @property string $nom
 * @property integer $telFix
 * @property integer $telMobil
 * @property string $eMail
 * @property string $web
 *
 * The followings are the available model relations:
 * @property Esdeveniments[] $esdeveniments
 */
class Organitzador extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organitzador the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'organitzador';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nom', 'required'),
			array('telFix, telMobil', 'numerical', 'integerOnly'=>true),
			array('nom, eMail, web', 'length', 'max'=>45),
            array('eMail', 'email'),
            array('web', 'url'),
            array('nom', 'unique', 'message'=>'Ja existeix un organitzador anomenat <b>{value}</b>.'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idOrganitzador, nom, telFix, telMobil, eMail, web', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'organitzadorEsdeveniments' => array(self::HAS_MANY, 'Esdeveniments', 'idOrganitzador'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idOrganitzador' => 'Codi',
			'nom' => 'Nom',
			'telFix' => 'Telèfon fix',
			'telMobil' => 'Telèfon mòbil',
			'eMail' => 'Correu electrònic',
			'web' => 'Pàgina web',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idOrganitzador',$this->idOrganitzador);
		$criteria->compare('nom',$this->nom,true);
		$criteria->compare('telFix',$this->telFix);
		$criteria->compare('telMobil',$this->telMobil);
		$criteria->compare('eMail',$this->eMail,true);
		$criteria->compare('web',$this->web,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
            'sort'=>array(
                'defaultOrder'=>array(
                    'nom'=>false, //false= ordre ascendent, true= ordre descendent
                )),
            'pagination'=>array(
                'pageSize'=>Yii::app()->params['itemsPagina']),
		));
	}
}